<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>Document</title>
</head>
<body>
	<div>gateway</div>
	<div>_key:{$key}</div>
	
	<div class='cr'></div>
</body>
<script src="__PUBLIC__/jquery.js"></script>
<script>
    var $URL = "__APP__/Home/GateWay/bindUid";
    // 与GatewayWorker建立websocket连接，域名和端口改为你实际的域名端口
    ws = new WebSocket("ws://127.0.0.1:8282");
    // 服务端主动推送消息时会触发这里的onmessage
    ws.onmessage = function(e){
        // json数据转换成js对象
        var data = eval("("+e.data+")");
        var type = data.type || ''; 
        console.log(e)
         switch(type){
            // Events.php中返回的init类型的消息，将client_id发给后台进行uid绑定
            case 'init':
                // 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
                $.post($URL, {client_id: data.client_id}, function(data){}, 'json');
                break;
            default :
            	var obj = JSON.parse(e.data);
            	var html = "<p>user-agent:"+obj.useragent+"</p>";
            	$('.cr').append(html);
               // alert(e.data);
        } 
    };
</script>
</html>

